package com.excesys.exsecs.energy.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.excel.annotation.ResponseExcel;
import com.excesys.exsecs.common.log.annotation.SysLog;
import com.excesys.exsecs.energy.entity.EnergyParamManage;
import com.excesys.exsecs.energy.service.EnergyParamManageService;
import com.excesys.exsecs.energy.service.EnergyParamStandardService;
import com.excesys.exsecs.energy.vo.EnergyParamManageVo;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 能源参数配置
 * @author zhang
 * @date 2024-09-26 10:29:19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/energyParamManage" )
@Tag(description = "energyParamManage" , name = "能源参数配置管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class EnergyParamManageController {

    private final  EnergyParamManageService energyParamManageService;
    private  final EnergyParamStandardService energyParamStandardService;

    /**
     * 分页查询
     * @param energyParamManage 能源参数配置
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('energy_energyParamManage_view')" )
    public R getEnergyParamManagePage(@ParameterObject EnergyParamManage energyParamManage) {
        return R.ok(energyParamManageService.queryAndEnergy());
    }


    /**
     * 通过id查询能源参数配置
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('energy_energyParamManage_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(energyParamManageService.getById(id));
    }

    /**
     * 新增能源参数配置
     * @param energyParamManage 能源参数配置
     * @return R
     */
    @Operation(summary = "新增能源参数配置" , description = "新增能源参数配置" )
    @SysLog("新增能源参数配置" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('energy_energyParamManage_add')")
    public R save(@RequestBody EnergyParamManageVo energyParamManage) {
        return R.ok(energyParamManageService.saveAndUpdate(energyParamManage));
    }

    /**
     * 修改能源参数配置
     * @param energyParamManage 能源参数配置
     * @return R
     */
    @Operation(summary = "修改能源参数配置" , description = "修改能源参数配置" )
    @SysLog("修改能源参数配置" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('energy_energyParamManage_edit')" )
    public R updateById(@RequestBody EnergyParamManage energyParamManage) {
        return R.ok(energyParamManageService.updateById(energyParamManage));
    }

    /**
     * 通过id删除能源参数配置
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除能源参数配置" , description = "通过id删除能源参数配置" )
    @SysLog("通过id删除能源参数配置" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('energy_energyParamManage_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(energyParamStandardService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param energyParamManage 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('energy_energyParamManage_export')" )
    public List<EnergyParamManage> export(EnergyParamManage energyParamManage,Long[] ids) {
        return energyParamManageService.list(Wrappers.lambdaQuery(energyParamManage).in(ArrayUtil.isNotEmpty(ids), EnergyParamManage::getId, ids));
    }






}